home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #1 / Amiga Plus CD - 2000 - No. 1.iso / Tools / Text / Edit / GoldED-Demo / installdata / golded / developer / scanner / examples / structures / struct.c
Encoding:
C/C++ Source or Header  |  1999-12-03  |  1.9 KB  |  82 lines

  1. /* -----------------------------------------------------------------------------
  2.  
  3.   Scan handler looking for C structures.
  4.   
  5.   Scan handlers are plain functions (loadSeg()'ed): no standard C startup
  6.   code and no library calls permitted. We have to put string constants into
  7.   the code segment (DICE compiler: option -ms1).
  8.  
  9.   DICE:
  10.   
  11.   dcc struct.c -// -l0 -md -mRR -o golded:etc/scanner/struct
  12.  
  13.   ------------------------------------------------------------------------------
  14. */
  15.  
  16. #include <exec/types.h>
  17.  
  18. #define UPPER(a) ((a) & 95)
  19.  
  20. ULONG
  21. ScanHandlerStruct(__D0 ULONG len, __A0 char **text, __A1 ULONG *line)
  22. {
  23.     const char *version = "$VER: Struct 1.2 (" __COMMODORE_DATE__ ")";
  24.  
  25.     UBYTE *from = *text;
  26.  
  27.     if (len > 8) {
  28.  
  29.         if ((from[0] == 't') && (from[1] == 'y') && (from[2] == 'p') && (from[3] == 'e') && (from[4] == 'd') && (from[5] == 'e') && (from[6] == 'f') && ((from[7] == ' ') || (from[7] == 9))) {
  30.  
  31.             // ignore typedef keyword
  32.  
  33.             len  -= 8;
  34.             from += 8;
  35.         }
  36.     }
  37.  
  38.     if (len > 7) {
  39.  
  40.         if ((from[0] == 's') && (from[1] == 't') && (from[2] == 'r') && (from[3] == 'u') && (from[4] == 'c') && (from[5] == 't') && ((from[6] == ' ') || (from[6] == 9))) {
  41.  
  42.             // found struct keyword
  43.  
  44.             UBYTE *last;
  45.  
  46.             for (last = from + len - 1; len && ((*last == 32) || (*last == 9)); --len)
  47.  
  48.                 --last;
  49.  
  50.             from += 7;
  51.             len  -= 7;
  52.  
  53.             if ((*last != ',') && (*last != '*')) {
  54.  
  55.                 UWORD pos = len;
  56.  
  57.                 // check if there is a ';' in this line
  58.  
  59.                 while (pos--)
  60.  
  61.                     if (from[pos] == ';')
  62.  
  63.                         return(FALSE);
  64.  
  65.                 if (*from != '{') {
  66.  
  67.                     *text = from;
  68.  
  69.                     for (len = 0; (from <= last) && (*from >= 48); ++len)
  70.  
  71.                         ++from;
  72.  
  73.                     return(len);
  74.                 }
  75.             }
  76.         }
  77.     }
  78.  
  79.     return(FALSE);
  80. }
  81.  
  82.